'use strict';

/**
 * @ngdoc function
 * @name jgappApp.controller:TaskTaskreportCtrl
 * @description
 * # TaskTaskreportCtrl
 * Controller of the jgappApp
 */
angular.module('jgappApp')
    .controller('TaskTaskreportCtrl', function ($scope, DataService, $timeout, localStorageService, $rootScope, PagingService, openApi, $location, $routeParams) {
        var vm = this;
        // type字符串类型防止0时判断错误
        vm.datalist = [
            {
                value: "未阅",
                type: "3"
            }, {
                value: "已阅",
                type: "2"
            }, {
                value: "已提交",
                type: "1"
            }, {
                value: "草稿",
                type: "0"
            }];
        // 默认缓存中取或者第一个
        vm.menutype = localStorageService.get("reportmenu") || vm.datalist[0].type;
        localStorageService.remove("reportmenu")
        vm.param = {};
        vm.switchmenu = function (type) {
            if (vm.menutype == type) {
                return;
            }
            vm.reportList.items = [];
            vm.menutype = type;
            $timeout(function () {
                vm.getReportData()
            }, 400)
        };
        vm.newReport = function () {
            $location.path("task/newreport")
        };
        vm.getReportData = function (option) {
            vm.param.flag = vm.menutype;
            var param = angular.extend(option || {}, vm.param)
            vm.reportList = new PagingService(openApi.getworklog, param);
        };
        vm.getMenuData = function () {
            var param = {};
            param.type = "工作报告类型";
            param.cache = true;
            DataService.getData(openApi.getKeyType, param).then(function (data) {
                vm.reportTypelist = data
            })
        };
        vm.goDetail = function (item) {
            localStorageService.set("reportpicker", vm.picker);
            localStorageService.set("reportmenu", vm.menutype);
            $location.path("task/reportdetail/" + vm.menutype + "/" + item.pkId)
        };
        vm.showSearch = function () {
            vm.picker = {};
            vm.showCerPicker = true;
            $rootScope.$emit('showmasker');
        }
        vm.cacelDialog = function () {
            vm.showCerPicker = false;
            $rootScope.$emit('closemasker');
        }
        $scope.$on('closemasker', function () {
            vm.cacelDialog()
        });
        vm.confirmDialog = function () {
            if (vm.picker.reportType || vm.picker.personName || vm.picker.title) {
                vm.getReportData(vm.picker);
                vm.cacelDialog()
            }
            vm.cacelDialog()
        };
        var init = function () {
            vm.getMenuData()
            var reportpicker = localStorageService.get("reportpicker");
            vm.getReportData(reportpicker);
        };
        init();
    });
